<?php
  class plugins extends admin{
    function make_extra($buff,&$buff){

      $this->apploadlib(KLEO_LIB_DIR."plugins.lib.php", "kleoplugins", $plugin);

      $plugins = $this->list_dir_files(substr(KLEO_PLUGINS_DIR,0,-1));
      $plugin->check_plugins();
      foreach($plugins as $p){
        if(file_exists(KLEO_PLUGINS_DIR.$p.'/package.xml') && !$plugin->is_added_plugin($p)){
           $plugin->add_plugin($p);
        }
      }

      if(isset($_GET['activate'])){
	$plugin->activate_plugin($_GET['activate']);
	$changed = true;
      } else if(isset($_GET['deactivate'])){
	$plugin->deactivate_plugin($_GET['deactivate']);
	$changed = true;
      }

      $pquery = "SELECT * FROM ".KLEO_TABLE_PREFIX."plugins ORDER BY pluid DESC";

      $captions = array(L_NAME,L_DESCRIPTION,L_VERSION,L_AUTHOR,L_ACTIONS);
      $values = array('name','description','version','author','actions');
      $sizes = array('fifteen','thirty','ten','twenty','fifteen');

      $a=0;
      $i=1;
      foreach($captions as $head){
	$this->list_heading[$a]['i'] = $i;
	$this->list_heading[$a]['caption'] = $head;
	$this->list_heading[$a]['size'] = $sizes[$a];
	$a++;
	$i++;
      }
      $this->list_data['heading'] = $this->list_heading;

      $i=0;
      $q = $this->query($pquery);
      while($row = $this->fetch_array($q)){
	$this->list_data['content'][$i]['value']="";
	$prow = $plugin->load_plugin_info($row['file']);

	$a=0;



	foreach($values as $value){
	  if(!$row[$value]){
	    $show_value = $prow[$value];
	  } else {
	    $show_value = $row[$value];
	  }
	 if(!isset($prow[$value])){
		$show_value = $prow['component'][$value];
	 }
	 if($value == 'author'){
		$show_value = '<a target="_blank" href="'.$prow['component']['author']['web'].'"><small>'.$prow['component']['author']['name'].'</small></a>';
	 }
	 if($value == 'actions'){
	  if((int)$row['status'] == 0){
	    $show_value = '<a href="?module=admin&file=plugins.tpl&activate='.$row['pluid'].'">Activate</a>';
	  } else {
	    $show_value = '<a href="?module=admin&file=plugins.tpl&deactivate='.$row['pluid'].'">Dectivate</a>';
	  }
	 $show_value = '<small>'.$show_value.' | <a href="?module=admin&file=manage_plugin.tpl&id='.$row['pluid'].'">'.L_MANAGE.'</a></small>';
	 }

	  $this->list_data['content'][$i]['value'] .= '<div class="'.$sizes[$a].'">'.$show_value.'</div>';
	$a++;
	}
      $i++;
      }

      $this->php_load('modules/admin/views/list_a.php', $factory_buff);
      $this->tpl_set("LIST", $factory_buff, $buff, $buff);

      $this->set_pagination_values(15, $pquery, null, $query);
      $this->generate_pagination_box($pagination_box, $pquery);

      $this->tpl_set(array(
	"PAGINATION_BOX" => $pagination_box,
	"ACTION_FILE" => $action_file,
	"TYPE" => $type
      ), false, $buff, $buff);

      if(!isset($_SESSION['dashboard_status']) && $changed){
	$_SESSION['dashboard_status'] = array(0,L_CHANGED_SUCCESFULLY);
      }

    }
  }
?>
